<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
  <!--<script src="http://{$Think.config.google_map_url}" async="async"></script>-->
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

</head>
<style>
  .layui-upload-img{
    width: 100px;!important;
  }
  .addclassify{
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 1px solid #666;
    line-height: 40px;
    border-radius: 40px;
    text-align: center;
    cursor: pointer;
  }
</style>
<body>
<div style="margin-top: 20px;">
</div>

<form class="layui-form" id="admin">

  <div class="layui-tab layui-tab-card" style="box-shadow:none">
    <ul class="layui-tab-title">
      <li class="layui-this">更新信息</li>
    </ul>
    <div class="layui-tab-content">
      <div class="layui-tab-item layui-show">
        <!--展示对比-->
        <input type="hidden" name="code" value="{$code}">
        {volist id='vo' name='data'}
        <p style="text-align: center;padding: 10px 0">{$vo.title}数据更新</p>
        <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98">
          <label class="layui-form-label">{$vo.title}最新数据 </label>
          <div class="layui-input-block" style="max-width:500px;">
            <textarea  class="layui-textarea" readonly >{$vo.newmsg}</textarea>
          </div>
        </div>
        <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98">
          <label class="layui-form-label">{$vo.title}历史数据 </label>
          <div class="layui-input-block" style="max-width:500px;">
            <textarea  class="layui-textarea" readonly >{$vo.oldmsg}</textarea>
          </div>
        </div>
        <div class="layui-form-item layui-form-text" style="position: relative ;z-index: 98">
          <label class="layui-form-label">{$vo.title}最终保存结果</label>
          <div class="layui-input-block" style="max-width:500px;">
            <textarea  class="layui-textarea" name="{$vo.key}" >{$vo.msg}</textarea>
          </div>
        </div>
        {/volist}
  </div>


  </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>

</form>

<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>

<script>
    layui.use(['layer', 'form','laydate','element'], function() {
        var $ = layui.jquery,
        laydate= layui.laydate
            , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        laydate.render({
            elem: '#start_goodstime' //指定元素
        });
        laydate.render({
            elem: '#end_goodstime' //指定元素
        });
    });


    $("#seeupload1").on("click",".layui-icon",function(){
        $(this).parent().remove();
        thumb("seeupload1",1);
    });

    function thumb(obj,n){
        var thumbs="";
        $("#"+obj).find("img").each(function(){
            var url=$(this).attr("src");
            thumbs+=","+url;
        });
        $("#upload-thumb"+n).val(thumbs);
    }

</script>




<script>

    var ue0 = UE.getEditor('jieshao');
    // var jieshao2 = UE.getEditor('jieshao2');
    var yongshi = UE.getEditor('yongshi');
    var baohan = UE.getEditor('baohan');
    var buhan = UE.getEditor('buhan');
    var zhuyi = UE.getEditor('zhuyi');
    var tuigai = UE.getEditor('tuigai');


    function muban(t){
        var op=""
            op+=" <option  value=''>请选择</option>"
        $.each(t,function (i,v) {
            op+="<option value='"+v.id+"'>"+v.name+"</option>"
        })
        return op;
    }

    function team(t){
        var op="";
        op+="  <option value=\"999999\">自营</option>";
        $.each(t,function (i,v) {
            op+="<option value='"+v.id+"'>"+v.name+"</option>"
        });
        op+="  <option value=\"1000000\">其他</option>";
        return op;
    }


  layui.use(['layer', 'form','laydate','layedit'], function() {
      // var laydate = layui.laydate;
    var layer = layui.layer,
            $ = layui.jquery,
        laydate= layui.laydate,
            form = layui.form;

      function changepoi(){
          var id=$("#relation_type").val();
          var city=$("#city").val();
          var goods_classify=$("#classify").val();

          if(id==0){
              $('#list option').remove();
              form.render('select');
              return false;
          }
          $.post("{:url('findpoi')}",
              {
                  'id':id,
                  'city':city,
                  'goods_classify':goods_classify,
              },
              function (date) {

                  var data =JSON.parse(date);
                  console.log(data);
                  $('#list option').remove();
                  $('#list').append(muban(data.poi));


                  $('#team_id option').remove();
                  $('#team_id').append(team(data.team));

                  form.render('select');
              })
      }

    $(window).on('load', function() {

        form.on('radio(poitype)', function(data){
            var val= $(this).val();
            $("#relation_type").val(val);

            changepoi()
        })


        $('#queding').click(function () {
           var id= $(this).attr("data-id");
            console.log(id)

        })



        form.on('select(city)', function(data){
            var id=data.value;
            $("#city").val(id);
            changepoi()
        });

        form.on('select(classify)', function(data){
            var id=data.value;
            $("#classify").val(id);
            changepoi()
        });


        form.on('select(addg)', function(data){
            var id=data.value;
           var sid= $('input[name="relation_type"]:checked').val();
          // console.log($id)
           $.post("{:url('xiala')}",{'sid':sid,'id':id},function (date) {
               var date=eval(date);
               ue0.setContent('');
               // jieshao2.setContent('');
               yongshi.setContent('');
               baohan.setContent('');
               buhan.setContent('');
               zhuyi.setContent('');
               tuigai.setContent('');

               if (date[0].hasOwnProperty('introduction') && date[0]['introduction']!==null){
                   ue0.setContent(date[0]['introduction']);
               }
               if (date[0].hasOwnProperty('price')  && date[0]['price']!==null){
                   baohan.setContent(date[0]['price']);
               }
               if (date[0].hasOwnProperty('priceno')  && date[0]['priceno']!==null){
                   buhan.setContent(date[0]['priceno']);
               }
               // if (date[0].hasOwnProperty('eng_introduce')  && date[0]['eng_introduce']!==null){
               //     jieshao2.setContent(date[0]['eng_introduce']);//英文简介
               // }
               if (date[0].hasOwnProperty('introduce')  && date[0]['introduce']!==null){
                   ue0.setContent(date[0]['introduce']);
               }

               if (date[0].hasOwnProperty('careful')  && date[0]['careful']!==null){
                   zhuyi.setContent(date[0]['careful']);
               }
               if (date[0].hasOwnProperty('back')  && date[0]['back']!==null){
                   tuigai.setContent(date[0]['back']);

               }


           });
        });



      function fuzhi($t){
          console.log($t)
          $.each($t ,function (i,v) {


              // console.log(v.introduction)

              // var ue0 = UE.getEditor('jieshao');
              // ue0.addListener('ready', function (editor) {
              //     console.log(v.introduction)
              //     // ue.setContent(json.Body.GoodDescription);
              //     ue0.setContent(v.introduction);
              // });


          })



      }

        //商品范围选择下拉添加事件
        //商品范围选择下拉添加事件
        form.on('select(addtrips)', function(data){
            var tripid=data.value;
            $("#addtrips").attr("data-id",tripid);
        });

        $("#addtrips").on("click",function () {
            var tripid= $("#addtrips").attr("data-id");
            var tripids=$("#tripids").val();
            var ids=tripids.split(",");

            if (tripid==999999){
                tripids=999999;
                var tripspan='<span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="999999" style="margin: 5px 10px">全部<i class="layui-icon"></i></span>';
                $("#tripnames").html(tripspan);
            }else{

                for(var i=0 ; i < ids.length; i++){
                    if(tripid==ids[i]){
                        layer.msg("不能重复添加商品");
                        return false;
                    }
                    if(ids[i]==999999){
                        tripids=999999;
                        var tripspan='<span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="999999" style="margin: 5px 10px">全部<i class="layui-icon"></i></span>';
                        $("#tripnames").html(tripspan);
                        $("#tripids").val(tripids);
                        return false;
                    }
                }
                var tripname="";
                $("#trip").find("option").each(function () {
                    if($(this).val()==tripid){
                        tripname=$(this).html();
                    }
                });

                var tripspan='<span class="layui-btn layui-btn-sm layui-btn-normal deltripspan" data-id="'+tripid+'" style="margin: 5px 10px">'+tripname+'<i class="layui-icon"></i></span>';

                if(!tripids){
                    tripids+=tripid;
                }else{
                    tripids+=','+tripid;
                }
                $("#tripnames").append(tripspan);
            }



            $("#tripids").val(tripids);
        })






        $(document).on("click",'.deltripspan',function () {
            var dataid=$(this).attr("data-id");
            var tripids=$("#tripids").val();
            var ids=tripids.split(",");
            var newid="";
            for(var i=0 ; i < ids.length; i++){
                if(ids[i]&&dataid!=ids[i]){
                    if(!newid){
                        newid+=ids[i];
                    }else{
                        newid+=","+ids[i];
                    }
                }
            }
            $("#tripids").val(newid);
            $(this).remove();
        })



      form.on('submit(admin)', function(data) {

        $.ajax({
          url:"{:url('admin/goods/changDetailT')}",
          data:$('#admin').serialize(),
          type:'post',
          async: false,
          success:function(res) {
            layer.msg(res.msg);
            if(res.code == 1) {
              setTimeout(function(){
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
              },1500)
            }
          }
        })
        return false;
      });
    });
  });
</script>

<!-- 实例化编辑器 -->
<script type="text/javascript">


</script>
</body>
</html>
